package edu.umn.msse.farside.FourH.web;

import edu.umn.msse.farside.FourH.domain.Event;
import edu.umn.msse.farside.FourH.domain.Position;
import edu.umn.msse.farside.FourH.services.EventService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * Created by IntelliJ IDEA.
 * User: corcutt
 * Date: Mar 23, 2009
 * Time: 8:20:54 PM
 * To change this template use File | Settings | File Templates.
 */
@Controller
@RequestMapping("/deletePosition")
public class DeletePositionController
{
    private EventService eventService;

    @Autowired
    public void setEventService(EventService eventService)
    {
        this.eventService = eventService;
    }

    @RequestMapping(method = {RequestMethod.GET, RequestMethod.POST})
    public String deletePositionSubmit(@RequestParam(required=true) Long positionID, @RequestParam(required=true) Long eventID) {
        Event event = eventService.getEvent(eventID);
        Position position = eventService.getPosition(positionID);
        eventService.removePosition(event, position);
        event = eventService.updateEvent(event);

        return "redirect:editEvent?eventID="+eventID;
    }

}
